package serializer

import (
	"go-shop-admin/internal/model"
	"go-shop-admin/pkg/funs"
	"time"
)

//定义返回给前端一些需要展示的数据 VO层
//VO（View Object）：视图对象，用于展示层，它的作用是把某个指定页面（或组件）的所有数据封装起来。

type UserVO struct {
	ID      uint   `json:"id" _:"comment:登录账号"`
	Account string `json:"account"  _:"comment:登录账号"`
	Desc    string ` json:"desc" _:"comment:描述"`
	Phone   string ` json:"phone" _:"comment:手机号"`
	Email   string ` json:"email"  _:"comment:邮箱"`
	Avatar  string ` json:"avatar" _:"comment:头像/微信头像本地地址"`
	//Username string  			`form:"username" json:"username" _:"type:varchar(100);comment:昵称/微信昵称"`
	Nickname string ` json:"nickname" _:"comment:昵称/微信昵称"`
	Sex      uint   ` json:"sex" _:"comment:性别/微信性别 0 未知 1 男 2 女"`
	Level    uint   `json:"level" _:"comment:会员等级 0 普通会员"`

	//小程序/公众号 永久二维码
	Ticket   string    ` json:"ticket" _:"comment:永久二维码ticket"`
	Status   uint      ` json:"status" _:"comment:状态:0 禁用 1 正常"`
	CreateAt time.Time ` json:"create_at" `
}

// UserinfoVo 用户信息
type UserinfoVo struct {
	Avatar   string `json:"avatar" _:"comment:头像/微信头像本地地址"`       //form:"avatar"
	Nickname string `json:"nickname" _:"comment:昵称/微信昵称"`         //form:"nickname"
	Desc     string `json:"desc" _:"comment:描述"`                  //form:"desc"
	Sex      uint   `json:"sex" _:"comment:性别/微信性别 0 未知 1 男 2 女"` //form:"sex"
	Level    uint   `json:"level" _:"comment:会员等级 0 普通会员"`        //form:"level"
	//积分
	//Integral      float64 `json:"integral" _:"comment:用户积分"`        //form:"integral"
	//UsedIntegral  float64 `json:"used_integral" _:"comment:已使用的积分"` //form:"used_integral"
	//TotalIntegral float64 `json:"total_integral" _:"comment:总积分"`   //form:"total_integral"
	//积分 - ase加密
	Integral      string `json:"integral" _:"comment:用户积分"`        //form:"integral"
	UsedIntegral  string `json:"used_integral" _:"comment:已使用的积分"` //form:"used_integral"
	TotalIntegral string `json:"total_integral" _:"comment:总积分"`   //form:"total_integral"
	//商城钱包 - 字符串，加码加密
	Wallet      string    `json:"wallet" _:"comment:商城钱包金额"`
	UsedWallet  string    `json:"used_wallet" _:"comment:已使用的钱包金额"`
	TotalWallet string    `json:"total_wallet" _:"comment:总钱包金额"`
	Status      uint      ` json:"status" _:"comment:状态:0 禁用 1 正常"`
	CreateAt    time.Time ` json:"create_at" `
}

// BuildUser 序列化
func BuildUser(user *model.User) *UserVO {
	return &UserVO{
		ID:       user.ID,
		Account:  user.Account,
		Desc:     user.Desc,
		Phone:    user.Phone,
		Email:    user.Email,
		Avatar:   funs.JointImageUrl(user.Avatar),
		Nickname: user.Nickname,
		Sex:      user.Sex,
		Level:    user.Level,
		Ticket:   user.Ticket,
		Status:   user.Status,
		CreateAt: user.CreatedAt,
	}
}

// BuildUserinfo 序列化
func BuildUserinfo(user *model.User, key string) *UserinfoVo {
	return &UserinfoVo{
		Avatar:        funs.JointImageUrl(user.Avatar),
		Nickname:      user.Nickname,
		Desc:          user.Desc,
		Sex:           user.Sex,
		Level:         user.Level,
		Integral:      funs.AesDeCoding(funs.CutStrNumByScene(user.Account, 6, 2), user.Integral),
		UsedIntegral:  funs.AesDeCoding(funs.CutStrNumByScene(user.Account, 6, 2), user.UsedIntegral),
		TotalIntegral: funs.AesDeCoding(funs.CutStrNumByScene(user.Account, 6, 2), user.TotalIntegral),
		Wallet:        funs.AesDeCoding(funs.CutStrNumByScene(user.Account, 6, 2), user.Wallet),
		UsedWallet:    funs.AesDeCoding(funs.CutStrNumByScene(user.Account, 6, 2), user.UsedWallet),
		TotalWallet:   funs.AesDeCoding(funs.CutStrNumByScene(user.Account, 6, 2), user.TotalWallet),
		Status:        user.Status,
		CreateAt:      user.CreatedAt,
	}
}
